package com.nuotu.datawall.clouddata;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.util.DialogSettings;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.MessageDialog;
import com.nuotu.datawall.clouddata.base.BaseActivity;
import com.nuotu.datawall.clouddata.control.Token;
import com.nuotu.datawall.clouddata.util.FinalStr;
import com.nuotu.datawall.clouddata.util.MessageDialogUtil;
import com.nuotu.datawall.clouddata.util.ServerConfig;
import com.nuotu.datawall.clouddata.util.Tool;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.Timer;
import java.util.TimerTask;

import me.wangyuwei.particleview.ParticleView;

@ContentView(R.layout.activity_splash)
public class LonginActivity extends BaseActivity {
    private Context content;

    @ViewInject(R.id.pv_logo)
    private ParticleView pv_logo;
    //echo 192.168.0.62 lib.test.net manage.test.net lib.android.net >> /system/etc/hosts
    private MessageDialog netErrorDialog;
    private Timer timer;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        timer=new Timer();
        if(!Tool.isNetWorkAvailable(mContext)){
            netErrorDialog= MessageDialogUtil.getInstance(mContext).showNetError(LonginActivity.this).setOkButton(new MessageDialogUtil.MessageOnDialogButtonClickListener() {
                @Override
                public void onRefresh() {
                    Tool.restartApplication(mContext);
                }
                @Override
                public boolean onClick(BaseDialog baseDialog, View v) {
                    Tool.restartApplication(mContext);
                    return false;
                }
            });
            return;
        }
        pv_logo = (ParticleView) findViewById(R.id.pv_logo);
        pv_logo.setOnParticleAnimListener(new ParticleView.ParticleAnimListener() {
            @Override
            public void onAnimationEnd() {
                Token.getInstance(mContext).setTokenTodoListener(new Token.TokenTodoListener() {
                    @Override
                    public void onGetTokenSuccess() {
                        Intent intent = new Intent(LonginActivity.this, MainActivity.class);
                        LonginActivity.this.startActivity(intent);
                        LonginActivity.this.finish();
                    }
                    @Override
                    public void onGetTokenError() {
                        Intent intent = new Intent(LonginActivity.this, MainActivity.class);
                        intent.putExtra(FinalStr.LOGIN_ERROR_KEY,"Y");
                        LonginActivity.this.startActivity(intent);
                        LonginActivity.this.finish();
                    }
                }).getToken();
            }
        });
        pv_logo.startAnim();

    }
    public void onCreate() {
        //初始化Handler
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
